<%-- 
    Document   : layout
    Created on : 24.11.2012, 10:12:33
    Author     : mprokes
--%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>

<f:message key="teams.index.title" var="title" /> 
<s:layout-render name="/layout.jsp" title="${title}">        
    <s:layout-component name="content">        
        <s:useActionBean beanclass="cz.muni.fi.pa165.sportclubmanager.web.TeamsActionBean" var="actionBean"/>           
        
        <h1><c:out value="${title}" /></h1>
        
        <div class="list-options">
            <sec:authorize access="hasRole('ROLE_ADMIN')">
                <s:link beanclass="${actionBean.getClass()}" event="edit" class="button">
                    <span class="icon icon-plus"></span> 
                    <f:message key="team.add.title" />
                </s:link>
            </sec:authorize>
        </div>

        <table class="table" width="100%" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <th class="table-column-id">id</th>
                    <th><f:message key="team.name"/></th>                
                    <th><f:message key="team.ageCategory.name"/></th>                
                    <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <th class="table-column-options"><f:message key="web.actions"/></th>                                
                    </sec:authorize>
                </tr>
            </thead>
            <tbody>
                <f:message key="action.showRoster" var="showRoosterMessage" />

                <c:choose>
                    <c:when test="${actionBean.teams == null || actionBean.teams.isEmpty()}">
                        <tr class="table-row-empty">
                            <td colspan="4">
                                <f:message key="web.tableIsEmpty" />
                            </td>
                        </tr>
                    </c:when>
                    <c:otherwise>
                        <c:forEach items="${actionBean.teams}" var="team">
                            <tr>
                                <td class="table-column-id">${team.id}</td>
                                <td>
                                    <s:link beanclass="cz.muni.fi.pa165.sportclubmanager.web.RostersActionBean" event="index" title="${showRoosterMessage}">
                                        <s:param name="team.id" value="${team.id}"/>
                                        ${team.name}
                                    </s:link>
                                </td>                    
                                <td>${team.ageCategory.name}</td>                    
                                <sec:authorize access="hasRole('ROLE_ADMIN')">
                                    <td class="table-column-options">
                                        <s:link beanclass="${actionBean.getClass()}" event="edit" title="${action.edit}">
                                            <s:param name="team.id" value="${team.id}"/>
                                            <span class="icon icon-edit"></span>
                                        </s:link> 
                                        <s:link beanclass="${actionBean.getClass()}" event="delete" title="${action.delete}" rel="delete-item">
                                            <s:param name="team.id" value="${team.id}"/>
                                            <span class="icon icon-delete"></span>
                                        </s:link>
                                    </td>
                                </sec:authorize>
                            </tr>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>
            </tbody>
        </table>

        <f:message key="team.action.delete.confirm" var="deleteConfirmMessage"/>

        <script>
            $(function() {
                $('[rel="delete-item"]').click(function() {
                    return confirm('${deleteConfirmMessage}');
                });
            })
        </script>
    </s:layout-component>        
</s:layout-render>